/* -----------------------------------------------------------------------
 * Christine Hayes
 * This is a modified version of my cardtest4.c file.
 * I have added to this original file the random components.
 * This is randomly testing the smithy card.
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include <time.h>
#include <stdlib.h>

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 0

int randomHand(int r) {
    int i;
	int hand[r];
	
	for (i = 0; i < r; i++)
    {
        if(i % 2 != 0){
			hand[i] = smithy;
		}else{
			hand[i] = gold;
		}
    }
	
	return *hand;
}

void runTest(int *hand, int size){
	int g;
    int seed = 1000;
    int numPlayer = 2;
    int maxBonus = 10;
    int p, r, handCount;
    int bonus;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int maxHandCount = size;

#if (NOISY_TEST == 1)
    printf ("TESTING smithy:\n");
#endif
    p = 0;
    
        for (handCount = 1; handCount <= maxHandCount; handCount++)
        {
            for (bonus = 0; bonus <= maxBonus; bonus++)
            {
#if (NOISY_TEST == 1)
                printf("Test player %d .\n", p);
#endif
                memset(&G, 23, sizeof(struct gameState));   // clear the game state
                r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
				g = handCount;
                G.handCount[p] = handCount;                 // set the number of cards on hand
				
                memcpy(G.hand[p], hand, sizeof(int) * handCount); // set all the cards to smithy
				
				cardEffect(smithy, 0, 0, 0, &G, 0, &bonus);
                
#if (NOISY_TEST == 1)
                printf("handCount = %d, expected = %d\n", G.handCount[p], g + 2); // original cards - 1 for the smithy played, + 3 (so +2)
#endif
                assert( G.handCount[p] == g + 2); // check if the number of cards is correct
            }
        }
    printf("All tests passed!\n");

    return;
}

int main(){
	srand(time(NULL));
	int i, r;
	
	for(i = 0; i < 100; i++){
		r =  (rand() % MAX_HAND ) + 1;
		int hand[r];
		*hand = randomHand(r);
		runTest(hand, r);
	}
	return 0;
}



